/*
 * Question: Try to propose a recursive algorithm
 * to swap every node's left subtree and right subtree
 * in a binary tree.
 */

#include <iostream>
#include "bitree.h"
using namespace std;

class bitree : public _bitree<bitree, char>
{
};

void swap_subtree(bitree *rt)
{
    bitree *t;

    if (!rt)
        return;
    t = rt->lchild;
    rt->lchild = rt->rchild;
    rt->rchild = t;
    swap_subtree(rt->lchild);
    swap_subtree(rt->rchild);
}

int main()
{
    bitree *rt;

    bitree_create<bitree, char>(rt, "ex43.txt");
    bitree_print(rt);
    swap_subtree(rt);
    bitree_print(rt);
    bitree_destory(rt);

    return 0;
}
